<%# locals: question, display_edit %>
<% if question.new_record? %>
  <div id="question_new">
<% else %>
  <div id=<%= raw "question_#{question.id}" %>>
<% end %>

<% if (!question.new_record?) && question.question_list.published %>

  <% #已发布版本，有评论，无直接修改 %>
  <% if question.topic.new_record? then question.topic.save end %>

  <p><%= render question.current_version %></p>
  <p><a data-switch-visible=<%= raw "question_remarks_#{question.id}" %>>
    <%= question.topic.remarks.count %>条评论
  </a></p>

  <div style="display:none" id=<%= raw "question_remarks_#{question.id}" %>>
    <%= render question.topic %>
  </div>

  <hr/>

<% else %>
  
  <% #未发布版本，新建用表单或显示可修改版本 %>
  <% if question.new_record? %>

    <% #新建 %>
    <div id="question_new">
      <div id=<%= raw "question_edit_new" %>>
        <%= render partial: 'questions/form', locals: { question: question } %>
      </div>
      <hr/>
    </div>

  <% else %>

    <% #可修改版本 %>
    <div id=<%= raw "question_#{question.id}" %>>

      <% if !defined? display_edit then display_edit = false end %>
      <% if question.current_version.errors.any? then display_edit = true end %>
      
      <% if display_edit %>
      <div style="display:none" id=<%= raw "question_show_#{question.id}" %>>
      <% else %>
      <div id=<%= raw "question_show_#{question.id}" %>>
      <% end %>
        <p><%= render question.current_version %></p>
        <p><a onClick=<%= raw"\"open_edit('question', '#{question.id}')\"" %>>编辑</a></p>
      </div>

      <% if display_edit %>
      <div id=<%= raw "question_edit_#{question.id}" %>>
      <% else %>
      <div style="display:none" id=<%= raw "question_edit_#{question.id}" %>>
      <% end %>

        <%= render partial: 'questions/form', locals: { question: question } %>

      </div>

      <hr/>
    </div>

  <% end %>

<% end %>

</div>
